package cn.tedu.ivos.vehicle.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleSaveParam;
import cn.tedu.ivos.vehicle.pojo.entity.Vehicle;
import cn.tedu.ivos.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.spring.web.json.Json;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/vehicle/")
public class VehicleController {
    @Autowired
    private VehicleService vehicleService;

    @GetMapping("select")
    public JsonResult query(VehicleQuery vehicleQuery) {
        log.debug("vehicleQuery = ", vehicleQuery);
        List<VehicleVO> list = vehicleService.query(vehicleQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    public JsonResult save(VehicleSaveParam vehicleSaveParam) {
        vehicleService.save(vehicleSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("del/{id}")
    public JsonResult del(@PathVariable Long id) {
        vehicleService.del(id);
        return JsonResult.ok();
    }

    @PostMapping("unbind/{VehicleId}")
    public JsonResult unBind(@PathVariable Long VehicleId) {
        vehicleService.unbind(VehicleId);
        return JsonResult.ok();
    }


//    可以复用select  传固定参数
    @GetMapping("selectUnBindVehicle")
    public JsonResult selectUnBindVehicle()
    {
        List<VehicleVO> list =  vehicleService.selectUnBindVehicle();
        return JsonResult.ok(list);
    }

//    传过来的 和 接接收的顺序必须一致
    @PostMapping("bind/{vehicleid}/{geoid}")
    public JsonResult bind(@PathVariable Long vehicleid,@PathVariable Long geoid){
        vehicleService.bind(vehicleid,geoid);
        return JsonResult.ok();
    }




}
